<script setup lang="ts">
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

onMounted(() => {
  // 检查是否是普通用户
  const userRole = sessionStorage.getItem('userRole')
  if (userRole !== 'user') {
    router.push('/404')
  }
})

function logout() {
  // 清除登录信息
  sessionStorage.removeItem('isLoggedIn')
  sessionStorage.removeItem('userRole')
  // 跳转到登录页
  router.push('/')
}

function goToProfile() {
  router.push('/user/profile')
}
</script>

<template>
  <div class="user-home">
    <header class="header">
      <h1>用户中心</h1>
      <button @click="logout" class="logout-btn">退出登录</button>
    </header>
    
    <div class="content">
      <div class="welcome-box">
        <h2>欢迎回来，用户</h2>
        <p>这是一个动态路由演示系统，您现在正在访问仅限普通用户角色可见的页面</p>
      </div>
      
      <div class="features-container">
        <div class="feature-card" @click="goToProfile">
          <div class="feature-icon">👤</div>
          <h3>个人资料</h3>
          <p>查看和编辑您的个人信息</p>
        </div>
        
        <div class="feature-card">
          <div class="feature-icon">📚</div>
          <h3>我的内容</h3>
          <p>管理您发布的内容</p>
        </div>
        
        <div class="feature-card">
          <div class="feature-icon">🔔</div>
          <h3>消息通知</h3>
          <p>查看系统通知和消息</p>
        </div>
        
        <div class="feature-card">
          <div class="feature-icon">⭐</div>
          <h3>收藏夹</h3>
          <p>查看您收藏的内容</p>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.user-home {
  min-height: 100vh;
  background-color: #f0f2f5;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background-color: #42b883;
  color: white;
}

.logout-btn {
  padding: 0.5rem 1rem;
  background-color: rgba(255, 255, 255, 0.2);
  border: 1px solid white;
  color: white;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.logout-btn:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

.content {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.welcome-box {
  background-color: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  margin-bottom: 2rem;
}

.welcome-box h2 {
  color: #42b883;
  margin-top: 0;
}

.features-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
}

.feature-card {
  background-color: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: all 0.3s;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.feature-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.feature-card h3 {
  margin: 0.5rem 0;
  color: #333;
}

.feature-card p {
  margin: 0;
  color: #666;
  font-size: 0.9rem;
}
</style> 